import { reactive } from 'vue'
import { schemaList, tableOrViewList } from "@/api/data-object"
export default function addForm(sjy: any) {
    const addStore = reactive({
        user: [],
        tableNameList: [],
        addForm: {
            id: '',
            ywlxmc: '',
            isMulti: 0,
            sjylx: '',
            sjymc: '',
            sjyfl: '',
            sjyid: "",
            ssyh2: '',
            sjdxlx2: '',
            tablesql: '',
            zdsql: '',
            ssyh: '',
            sjdxlx: '',
            filter: '',
            zhsjdxmcBM: '',
            zhsjdxmcZWM: '',
            zhsjdxmcBZ: '',
            zhsjzdmcBM: '',
            zhsjzdmcZDMC: '',
            zhsjzdmcZDMS: '',
            sjdxmc: '',
            sjdxms: '',
            ywlxid: '',
            sjdxtb: '',
            bz: '',
        },
        handleChange: (value: string) => {
            const { sjylx, sjymc, sjyfl } = sjy.value.filter((item: any) => value === item.id)[0]
            addStore.addForm.sjylx = sjylx;
            addStore.addForm.sjymc = sjymc;
            addStore.addForm.sjyfl = sjyfl;
            schemaList(value).then(({ items }: any) => {
                addStore.user = items;
            });
        },
        handleChangeType: (value: string) => {
            tableOrViewList(addStore.addForm.sjyid, addStore.addForm.ssyh, value).then(({ items }: any) => {
                addStore.tableNameList = items;
            });
        },
    })

    const rulesRefAdd = reactive({
        sjyid: [{ required: true, message: "" }],
        ssyh: [{ required: true, message: "" }],
        sjdxlx: [{ required: true, message: "" }],
        sjdxmc: [{ required: true, message: "" }],
        sjdxms: [{ required: true, message: "" }],
        ywlxid: [{ required: true, message: "" }],
    });

    const rulesRefAdd_tow = reactive({
        sjyid: [{ required: true, message: "" }],
        ssyh: [{ required: true, message: "" }],
        sjdxlx: [{ required: true, message: "" }],
    });

    return {
        addStore,
        rulesRefAdd,
        rulesRefAdd_tow
    }
}